package com.hilon.segment.mybatis.service.impl;

import com.hilon.segment.mybatis.utils.ResultBean;
import com.hilon.segment.mybatis.mapper.system.SysMenuMapper;
import com.hilon.segment.mybatis.mapper.system.SysRoleMapper;
import com.hilon.segment.mybatis.pojo.po.system.SysMenuDo;
import com.hilon.segment.mybatis.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class AuthServiceImpl implements AuthService {

    @Resource
    private SysRoleMapper sysRoleMapper;

    @Resource
    private SysMenuMapper sysMenuMapper;

    /**
     * 通过当前用户名查找用户系统菜单.
     *
     * @return 返回当前用户的菜单.
     */
    @Override
    public ResultBean<List<SysMenuDo>> listMenuByCurrentUser(String username) {
        List<String> roleNameList = sysRoleMapper.listRoleNameFromUserAndUserGroupByUsername(username);
        if (roleNameList == null || roleNameList.size() == 0) {
            return new ResultBean<>();
        }
        List<SysMenuDo> menuDoList = sysMenuMapper.listMenuByRoleName(roleNameList);
        return new ResultBean<>(menuDoList);
    }
}
